package com.amado.easyui2.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 数据库连接
 */
public class DBConnection {
	private static String url = PropertiesUtil.getProperty("url");
	private static String driverClasssName = PropertiesUtil.getProperty("driverClasssName");
	private static String user = PropertiesUtil.getProperty("user");
	private static String password = PropertiesUtil.getProperty("password");

	public static Connection getConn() {
		try {
			Class.forName(driverClasssName);
			return DriverManager.getConnection(url, user, password);
		} catch (SQLException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
	// 关闭数据库
    public static void close(ResultSet rs, Statement state, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            rs = null;
        }
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            state = null;
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            conn = null;
        }
    }
	// 测试数据库连接是否成功
	public static void main(String[] args) {
		System.out.println(getConn());
	}
}